<template>
  <div class="header">
    <Header :title="'预警信息'"></Header>
  </div>
  <div class="content">
    <div class="picture_main card">
      <div class="carousel">
        <el-carousel height="380px" :autoplay="false">
          <el-carousel-item v-for="item in imgList" :key="item">
            <img :src="item.imgUrl" style="height: 100%; width: 100%" />
          </el-carousel-item>
        </el-carousel>
      </div>
      <div class="msg_list">
        <div class="msg_item card" v-for="(item, i) in msgList" :key="i">
          <div class="msg_label">{{ item.label }}</div>
          :
          <el-tooltip
            :disabled="!tooltipFlag"
            effect="light"
            :content="item.msg"
          >
            <div class="msg_content" @mouseenter="visibilityChange($event)">
              {{ item.msg }}
            </div>
          </el-tooltip>
        </div>
      </div>
    </div>
    <div class="msg_list card">
      <div class="title"><h2>作物生长情况预警</h2></div>
      <div class="msg_scroll">
        <div class="mag_item" v-for="(item, i) in warningList" :key="i">
          <div class="no">{{ i+1 }}.</div>
          <div class="msg">{{ item.msg }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { reactive, ref } from "vue"
import Header from "@/components/header/header.vue"

const imgList = reactive([
  {
    imgUrl: new URL("@/assets/images/1.jpg", import.meta.url).href,
  },
  {
    imgUrl: new URL("@/assets/images/2.jpg", import.meta.url).href,
  },
  {
    imgUrl: new URL("@/assets/images/3.jpg", import.meta.url).href,
  },
  {
    imgUrl: new URL("@/assets/images/4.jpg", import.meta.url).href,
  },
  {
    imgUrl: new URL("@/assets/images/5.jpg", import.meta.url).href,
  },
])

const msgList = reactive([
  {
    label: "1号标签",
    msg: "疑似叶霉病，概率62%",
  },
  {
    label: "2号标签",
    msg: "疑似细菌斑点病，概率63%",
  },
  {
    label: "3号标签",
    msg: "疑似叶霉病，概率62%",
  },
  {
    label: "4号标签",
    msg: "疑似叶霉病，概率83%",
  },
  {
    label: "5号标签",
    msg: "疑似叶霉病，概率60%",
  },
])

const warningList=reactive([
  {
    msg:"2号棚5号地块疑似出现叶霉病，建议适量喷洒多抗霉素。"
  },
  {
    msg:"1号棚4号地块疑似出现细菌性斑点病，需喷洒百菌清或甲基硫菌灵。"
  },
  {
    msg:"1号棚2号地块出现大面积早疫病，建议适量增施稻壳，加快排水，改善土壤环境并增大光照。"
  }
])

// tooltip的可控
const tooltipFlag = ref(false)
const visibilityChange = (event: any) => {
  const el = event.target
  if (el.clientWidth < el.scrollWidth) {
    // 实际内容高度 > 文本高度 =》内容溢出
    tooltipFlag.value = true
  } else {
    // 否则为不溢出
    tooltipFlag.value = false
  }
}
</script>

<style lang="scss" scoped>
.header {
  width: 100%;
  height: 50px;
}
.content {
  display: flex;
  width: 100%;
  height: calc(100% - 52px);
  .picture_main {
    width: calc(75% - 32px);
    margin: 16px;
    .carousel {
      height: calc(65% - 16px);
      padding: 16px;
      border-bottom: 2px solid var(--border-common);
      :deep(.el-carousel) {
        height: 100%;
        .el-carousel-item {
          text-align: center;
        }
      }
    }
    .msg_list {
      height: calc(35% - 48px);
      width: calc(100% - 32px);
      margin-top: 16px;
      padding: 0 16px;
      overflow-y: scroll;
      .msg_item {
        display: flex;
        width: calc(100% - 32px);
        padding: 16px 16px;
        margin-bottom: 12px;
        .msg_label {
          min-width: 80px;
        }
        .msg_content {
          width: calc(100% - 58px);
          margin-left: 8px;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }
      }
    }
  }
  .msg_list {
    width: calc(25% - 16px);
    height: calc(100% - 32px);
    margin-top: 16px;
    .title {
      height: 50px;
      line-height: 50px;
      text-align: center;
      color: rgb(245, 170, 9);
      letter-spacing: 2px;
      border-bottom: 1px solid var(--main-card-shadow);
    }
    .msg_scroll {
      height: calc(100% - 82px);
      padding: 16px;
      .mag_item {
        display: flex;
        line-height: 35px;
        font-size: 16px;
        word-break: break-all;
        word-wrap: wrap;
        border-bottom: 1px solid var(--main-border-color);
        .no {
          width: 30px;
          height: 100%;
        }
        .msg {
          width: calc(100% - 30px);
        }
      }
    }
  }
}
</style>
